package com.hanyizhu.demostore.controller;

import com.hanyizhu.demostore.entity.Product;
import com.hanyizhu.demostore.service.IProductService;
import com.hanyizhu.demostore.util.JsonResult;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author lenovo
 */
@RestController
@RequestMapping("/products")
public class ProductController extends BaseController{

    @Autowired
    private IProductService productService;
    @RequestMapping("/hot_list")
    public JsonResult<List<Product>> findHotList(){
        List<Product> data = productService.findHotList();
        return new JsonResult<List<Product>>(OK,data);
    }

    @RequestMapping("{id}/details")
    public JsonResult<Product> getfindById(@PathVariable("id") Integer id){
        Product data = productService.findById(id);
        return new JsonResult<>(OK,data);
    }
}
